<?php
if (file_exists('local_config.php')) include('local_config.php');
else include('local_config.default.php');


$QUERY_PLAYLISTCONTENT_BYNAME = 'select trackindex, '.$DATABASE_TABLE_PREFIX.'playlist_content.trackid, '.$DATABASE_TABLE_PREFIX.'tracks.* from '.$DATABASE_TABLE_PREFIX.'playlist_content, '.$DATABASE_TABLE_PREFIX.'playlist_info, '.$DATABASE_TABLE_PREFIX.'tracks where '.$DATABASE_TABLE_PREFIX.'playlist_content.playlistid = '.$DATABASE_TABLE_PREFIX.'playlist_info.playlistid and '.$DATABASE_TABLE_PREFIX.'playlist_info.name = "&PLAYLISTNAME" and '.$DATABASE_TABLE_PREFIX.'playlist_content.trackid = '.$DATABASE_TABLE_PREFIX.'tracks.trackid order by '.$DATABASE_TABLE_PREFIX.'playlist_content.trackindex;';
$QUERY_PLAYLISTCONTENT_BYID = 'select trackindex, '.$DATABASE_TABLE_PREFIX.'playlist_content.trackid, '.$DATABASE_TABLE_PREFIX.'tracks.* from '.$DATABASE_TABLE_PREFIX.'playlist_content, '.$DATABASE_TABLE_PREFIX.'playlist_info, '.$DATABASE_TABLE_PREFIX.'tracks where '.$DATABASE_TABLE_PREFIX.'playlist_content.playlistid = '.$DATABASE_TABLE_PREFIX.'playlist_info.playlistid and '.$DATABASE_TABLE_PREFIX.'playlist_info.playlistid = "&PLAYLISTID" and '.$DATABASE_TABLE_PREFIX.'playlist_content.trackid = '.$DATABASE_TABLE_PREFIX.'tracks.trackid order by '.$DATABASE_TABLE_PREFIX.'playlist_content.trackindex;';
$QUERY_LISTPLAYLISTS_WITHCOUNT = 'select '.$DATABASE_TABLE_PREFIX.'playlist_info.*, count(trackindex) from '.$DATABASE_TABLE_PREFIX.'playlist_content inner join '.$DATABASE_TABLE_PREFIX.'playlist_info on '.$DATABASE_TABLE_PREFIX.'playlist_content.playlistid = '.$DATABASE_TABLE_PREFIX.'playlist_info.playlistid group by playlistid, name;';
$QUERY_LISTPLAYLISTS = 'select * from '.$DATABASE_TABLE_PREFIX.'playlist_info;';
$QUERY_SEARCH_TRACKS = 'select * from '.$DATABASE_TABLE_PREFIX.'tracks where title like "%&NEEDLE%" or artist like "%&NEEDLE%" or album like "%&NEEDLE%";';
$QUERY_COUNT_TRACKS = 'select count(*) from '.$DATABASE_TABLE_PREFIX.'tracks;';

function Q_PlaylistContentByName	($playlistName)	{global $QUERY_PLAYLISTCONTENT_BYNAME;return str_replace('&PLAYLISTNAME',$playlistName,  $QUERY_PLAYLISTCONTENT_BYNAME);}
function Q_PlaylistContentByID		($playlistID) 	{global $QUERY_PLAYLISTCONTENT_BYNAME;return str_replace('&PLAYLISTID',$playlistName,  $QUERY_PLAYLISTCONTENT_BYNAME);}
function Q_ListPlaylistsWithCount	()				{global $QUERY_LISTPLAYLISTS_WITHCOUNT;return $QUERY_LISTPLAYLISTS_WITHCOUNT;}
function Q_ListPlaylists			()				{global $QUERY_LISTPLAYLISTS;return $QUERY_LISTPLAYLISTS;}
function Q_SearchTracks				($s)			{global $QUERY_SEARCH_TRACKS;return str_replace('&NEEDLE',$s, $QUERY_SEARCH_TRACKS);}
function Q_CountTracks				()				{global $QUERY_COUNT_TRACKS; return $QUERY_COUNT_TRACKS;}


?>